<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
 <%@ page import="java.sql.*;"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	String passport = request.getParameter("passport");
	String password = request.getParameter("password");

	if( passport==null ) {
		response.sendRedirect("index.jsp");
		return;
	}

	try {
		Class.forName("com.mysql.jdbc.Driver");
	} catch (ClassNotFoundException e) {
		out.print(e);
	}
	
	Connection con;
  Statement sql;
  ResultSet rs;

  String url = "jdbc:mysql://localhost:3306/bookinfo?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull";
  String user = "root";
  String psword = "chuichuiqqt";

  try { 
  	con=DriverManager.getConnection(url,user,psword);
      sql=con.createStatement();
      rs=sql.executeQuery("select * from user where username='" + passport + "' and password='" + password + "'" );
      if(rs.next()) {
      	session.setAttribute("passport",rs.getString("username"));
      	response.sendRedirect("home.jsp");
    	} else {
    		request.getRequestDispatcher("index.jsp").forward(request,response);
    	}
 	} catch(SQLException e) { 
      out.print(e);
  }
%>